﻿#include "DialogCurveSmoothing.h"
#include "ui_DialogCurveSmoothing.h"
#include "IdaWidgetHelper.h"
#include "CenterWidget.h"
#include "LineChartWindow.h"
#include <QDebug>
#include "BaseModule/IBaseSignal.h"

namespace pst
{
    DialogCurveSmoothing::DialogCurveSmoothing(QWidget* parent, LineChartWindow* lineChartWindow)
        : IdaDialogFrame(parent)
        , ui(new Ui::DialogCurveSmoothing())
    {
        ui->setupUi(this);
        m_lineChartWindow = lineChartWindow;
        setWindowTitle(tr("曲线平滑"));
        IdaWidgetHelperInstance->setMainButtonStyle(ui->pushButton_confirm); // 将确定设置为主按钮
    }

    DialogCurveSmoothing::~DialogCurveSmoothing()
    {
        delete ui;
    }

    void DialogCurveSmoothing::setInit(QStringList& params)
    {
        if (params.at(0) != "6")
            return;
        params.removeFirst();
        ui->doubleSpinBox->setValue(params.first().toDouble() * 100);
    }

    void DialogCurveSmoothing::on_pushButton_confirm_clicked()
    {
        if (m_lineChartWindow == nullptr)
            return;

        m_lineChartWindow->slot_smoothData(ui->doubleSpinBox->value() / 100);
        QString _pyCode = QString("PostProcessing.lineChartDialogCurveSmoothing(%1)")
                              .arg(ui->doubleSpinBox->value() / 100);
        emit IBaseSignalInstance->signal_execPYCode(QStringList{_pyCode}, true, false);
        this->close();
    }

    void DialogCurveSmoothing::on_pushButton_cancel_clicked()
    {
        this->close();
    }
}
